# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=allegro
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.2.8.0
pkgrel=2
pkgdesc="Portable library mainly aimed at video game and multimedia programming (mingw-w64)"
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url="https://liballeg.org/"
license=('spdx:Zlib')
depends=("${MINGW_PACKAGE_PREFIX}-dumb"
         "${MINGW_PACKAGE_PREFIX}-flac"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libogg"
         "${MINGW_PACKAGE_PREFIX}-libtheora"
         "${MINGW_PACKAGE_PREFIX}-libvorbis"
         "${MINGW_PACKAGE_PREFIX}-libwebp"
         "${MINGW_PACKAGE_PREFIX}-openal"
         "${MINGW_PACKAGE_PREFIX}-opusfile"
         "${MINGW_PACKAGE_PREFIX}-physfs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
source=(${_realname}-${pkgver}.tar.gz::https://github.com/liballeg/allegro5/archive/${pkgver}.tar.gz)
conflicts=("${MINGW_PACKAGE_PREFIX}-allegro-static")
provides=("${MINGW_PACKAGE_PREFIX}-allegro-static")
noextract=(${_realname}-${pkgver}.tar.gz)
sha256sums=('f509f07dc333231dedc44048a187fe92582daf3c2c35c53d9c13d47dd7d46ea8')

prepare() {
  rm -rf ${_realname}5-${pkgver}
  tar -xf ${_realname}-${pkgver}.tar.gz || true
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DWANT_DOCS=OFF \
    -DINSTALL_PKG_CONFIG_FILES=ON \
    ../${_realname}5-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install ./
  install -Dm644 "${srcdir}/${_realname}5-${pkgver}/LICENSE.txt" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.txt"
}
